<?php
/**
 * Created by PhpStorm.
 * User: Aliaksei Lazerka
 * Date: 10/24/14
 * Time: 9:10 PM
 */

include_once("functions/db_manipulate.php");

$defaultFields = array('ID', 'CLS_ID');

$output = "<table cellspacing='0' cellpadding='0' style='text-align: center; margin-top:10px; margin-bottom:10px; border: 1px solid rgba(0,0,0,0.3); border-collapse: collapse'>";

$products = getProducts($_POST['listSubId'], $_POST['sectionId']);

if ($row = mysql_fetch_assoc($products)) {
  $output .= "<tr>";
  foreach ($row as $key => $value) {
    if (!in_array($key, $defaultFields)) {
      $output .= "<td style='border: 1px solid rgba(0,0,0,0.3); padding: 5px'>" . $key . "</td>";
    }
  }

  $output .= "<td style='border: 1px solid rgba(0,0,0,0.3); padding: 5px'>Действия</td>";
  $output .= "</tr><tr>";

  foreach ($row as $key => $value) {
    if (!in_array($key, $defaultFields)) {
      $value = $value == "" ? "-" : $value;
      $output .= "<td style='border: 1px solid rgba(0,0,0,0.3); padding: 5px'>" . $value . "</td>";
    }
  }
  $output .= "<td style='border: 1px solid rgba(0,0,0,0.3); padding: 5px' valign='center'><img src='../img/close_16.png' onclick=\"location.href='?ePH&pid=".$row['ID']."&sid=".$_POST['sectionId']."'\"/></td>";

  $output .= "</tr>";

  while ($row = mysql_fetch_assoc($products)) {
    $output .= "<tr>";
    foreach ($row as $key => $value) {
      if (!in_array($key, $defaultFields)) {
        $value = $value == "" ? "-" : $value;
        $output .= "<td style='border: 1px solid rgba(0,0,0,0.3); padding: 5px'>" . $value . "</td>";
      }
    }

    $output .= "<td style='border: 1px solid rgba(0,0,0,0.3); padding: 5px' valign='center'><img src='../img/close_16.png' onclick=\"location.href='?ePH&pid=".$row['ID']."&sid=".$_POST['sectionId']."'\"/></td>";

    $output .= "</tr>";
  }
}
$output .= "</table>";
echo $output;